//bange_box.hpp
//Copyright (C) 2010-2011 Oscar (.teri) Triano

//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program.  If not, see <http://www.gnu.org/licenses/>.

#ifndef _bange_box_
#define _bange_box_

#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <physfs.h>
#include <lua5.1/lua.hpp>
#include <SFML/Graphics.hpp>
#include <bange_vm.hpp>
#include <bange_base.hpp>
#include <bange_console.hpp>

using namespace std;

namespace bange{
	
	class box: public sf::RenderWindow{
		
		private:
			lua_State *vm;
			bool error;
			sf::RenderWindow *renderwindow;
			int callexitfunction;
			int dataexitfunction;
			sf::Key::Code exitkey;
			sf::Key::Code consolekey;
			bool consoleenabled;
			bange::console console;
			sf::Color bgcolor;
		public:
			box();
			void DrawConsole();
			bool Error(void);
			bool InitFromConsole(const char *);
			bool InitFromDesktop(void);
			bool Configure(void);
			void Run(void);
			void ManageEvent(sf::Event &);
			void ProcessScenes(void);
			void ProcessViews(void);
			void SetExitFunction(int function, int data);
			void CallExitFunction(void);
			void SetBgColor(int, int, int);
			void ManageEventForConsole(sf::Event &);		
			~box();
		private:
			void CreateEventData(sf::Event &);
			void CreateEventDataForView(sf::Event &, sf::View *view=NULL);
	};
	PHYSFS_sint64 readfilefrompackage(const char *filename, char **pbuffer);
	PHYSFS_sint64 readbinaryfrompackage(const char *filename, char **pbuffer);
	box *getbangebox(lua_State *vm);//Returns the current box object for be used
	
	void RegisterVM(lua_State *vm);
	
}

static int bangebox_SetExitFunction(lua_State *);
static int bangebox_SetBgColor(lua_State *);
static int bangebox_SetVSync(lua_State *);
static int bangebox_ShowCursor(lua_State *);
static int bangebox_SetKeyRepeat(lua_State *);
static int bangebox_SetFPS(lua_State *);
static int bangebox_GetTime(lua_State *);

#endif
